﻿using System.Windows.Controls;
using SnakeGame.ViewModels;
using System.Windows.Input;

namespace SnakeGame.Views
{
    /// <summary>
    /// Interaction logic for AnswerPage.xaml
    /// </summary>
    public partial class AnswerPage : Page
    {
        private AnswerPageViewModel _answerPage;
        private QuestionFrame _frame;

        public AnswerPage()
        {
            InitializeComponent();
        }

        public void Initialize(QuestionFrame qFrame, bool isWin)
        {
            _frame = qFrame;
            _answerPage = new AnswerPageViewModel();
            _answerPage.Initialize(qFrame, isWin);
            DataContext = _answerPage;
        }

        private void GoButton_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                _answerPage.GoCommand.Execute(sender);
            }
        }

        private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _frame.Window.KeyDown += GoButton_KeyDown;
        }

        private void Page_Unloaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _frame.Window.KeyDown -= GoButton_KeyDown;
        }
    }
}
